const path = require("path");

module.exports = {
  mode: "production",
  entry: "./index.ts",
  output: {
    filename: "index.js",
    path: path.resolve(__dirname, "dist"),
    // libraryTarget: "commonjs2",
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        use: "babel-loader",
        exclude: /node_modules/,
      },
      {
        test: /\.tsx?$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
          options: {
            presets: ["@babel/preset-env"],
            plugins: [
              "@babel/plugin-transform-runtime",
              "@babel/plugin-proposal-class-properties",
              "@babel/plugin-proposal-nullish-coalescing-operator",
              "@babel/plugin-proposal-optional-chaining",
            ],
          },
        },
      },
      {
        test: /\.tsx?$/,
        exclude: /node_modules/,
        loader: "ts-loader",
      },
      {
        test: /\.[(png)|(obj)|(json)]$/,
        loader: "file-loader",
      },
      {
        test: /\.svg$/,
        loader: "file-loader",
      },
      {
        test: /\.(le|c)ss$/,
        use: [
          "style-loader",
          "css-loader",
          {
            loader: "less-loader",
            options: {
              javascriptEnabled: true,
            },
          },
        ],
      },
      {
        test: /\.(woff|woff2|jpg|png)$/,
        use: {
          loader: "url-loader",
          options: {
            name: "images/[hash].[ext]",
            limit: 12 * 1024,
            mimetype: "application/font-woff",
          },
        },
      },
    ],
  },
  resolve: {
    alias: {
      antd: path.resolve(__dirname, "antd"),
      src: path.resolve(__dirname, "src"),
      components: path.resolve(__dirname, "components"),
    },
    extensions: [".ts", ".tsx", ".js", ".json"],
  },
};
